package ch04;

import java.util.ArrayList;
import java.util.List;

public class Graph {
    private final int V;
    private int E;
    private List<Integer>[] adj;



    public Graph(int v) {
        this.V = v;
        this.E = 0;
        adj = new ArrayList[V];
        for (int i = 0; i < adj.length; i++) {
            adj[i] = new ArrayList<>();
        }
    }

    public int V(){
        return this.V;
    }
    public int E(){
        return this.E;
    }
    public void addEdge(int v, int w) {
        adj[v].add(w);
        adj[w].add(v);
        E++;
    }

    public Iterable<Integer> adj(int v) {
        return adj[v];
    }


    public static void main(String[] args) {
        Graph graph = new Graph(9);
        graph.addEdge(1, 2);
        graph.addEdge(1, 3);
        graph.addEdge(4, 2);
        graph.addEdge(3, 4);
        Iterable<Integer> adj = graph.adj(1);
        adj.forEach((item)-> System.out.println(item));
    }
    public static Graph getGraphUseCase(){
        Graph graph = new Graph(100);
        graph.addEdge(2, 1);
        graph.addEdge(3, 2);
        graph.addEdge(4, 3);


        graph.addEdge(8, 6);
        graph.addEdge(6, 7);


        graph.addEdge(11, 12);

        return graph;
    }
}
